<template>
	<view class="container">
		<!-- 页面标题 -->
		<view class="page-header">
			<text class="page-title">首页</text>
		</view>
		
		<!-- 轮播图区域 -->
		<view class="carousel-section">
			<!-- 轮播图容器 -->
			<view class="carousel-container">
				<swiper 
					class="carousel" 
					:indicator-dots="false"
					:current="currentIndex"
					@change="onSwiperChange"
					:autoplay="true" 
					:interval="3000" 
					:duration="500"
				>
					<swiper-item v-for="(item, index) in carouselItems" :key="index" @click="onCarouselItemClick(item, index)">
						<view class="carousel-item">
							<text class="carousel-text">{{ item.text }}</text>
						</view>
					</swiper-item>
				</swiper>
				
				<!-- 自定义指示器 - 在轮播图内部底部 -->
				<view class="custom-indicators">
					<view 
						v-for="(item, index) in carouselItems" 
						:key="index"
						class="indicator-dot"
						:class="{ active: currentIndex === index }"
						@click="onIndicatorClick(index)"
					></view>
				</view>
			</view>
		</view>

		<!-- 门诊服务板块 -->
		<view class="service-section">
			<view class="section-header">
				<view class="section-line"></view>
				<text class="section-title">门诊服务</text>
			</view>
			
			<!-- 突出功能块 -->
			<view class="feature-cards">
				<view class="feature-card feature-card-red">
					<view class="feature-content">
						<text class="feature-title">预约挂号</text>
						<text class="feature-subtitle">在线挂号预约</text>
					</view>
					<view class="feature-icon feature-icon-red"></view>
				</view>
				<view class="feature-card feature-card-green">
					<view class="feature-content">
						<text class="feature-title">在线充值</text>
						<text class="feature-subtitle">就诊卡预存充值</text>
					</view>
					<view class="feature-icon feature-icon-green"></view>
				</view>
			</view>

			<!-- 服务按钮网格 -->
			<view class="service-grid">
				<view
					class="service-item"
					v-for="service in outpatientServices"
					:key="service.id"
					@click="handleServiceClick(service)"
				>
					<view class="service-icon" :class="`service-icon-${service.id}`"></view>
					<text class="service-text">{{ service.name }}</text>
				</view>
			</view>
		</view>

		<!-- 住院服务板块 -->
		<view class="service-section">
			<view class="section-header">
				<view class="section-line"></view>
				<text class="section-title">住院服务</text>
			</view>
			<view class="service-grid">
				<view
					class="service-item"
					v-for="service in inpatientServices"
					:key="service.id"
					@click="handleServiceClick(service)"
				>
					<view class="service-icon" :class="`service-icon-${service.id}`"></view>
					<text class="service-text">{{ service.name }}</text>
				</view>
			</view>
		</view>

		<!-- 医院服务板块 -->
		<view class="service-section">
			<view class="section-header">
				<view class="section-line"></view>
				<text class="section-title">医院服务</text>
			</view>
			<view class="service-grid">
				<view
					class="service-item"
					v-for="service in hospitalServices"
					:key="service.id"
					@click="handleServiceClick(service)"
				>
					<view class="service-icon" :class="`service-icon-${service.id}`"></view>
					<text class="service-text">{{ service.name }}</text>
				</view>
			</view>
		</view>

		<!-- 底部导航 -->
		<view class="bottom-nav">
			<view class="nav-item" :class="{ 'nav-item-active': currentTab === 'home' }" @click="switchTab('home')">
				<view class="nav-icon nav-icon-home"></view>
				<text class="nav-text">首页</text>
			</view>
			<view class="nav-item" :class="{ 'nav-item-active': currentTab === 'personal' }" @click="switchTab('personal')">
				<view class="nav-icon nav-icon-person"></view>
				<text class="nav-text">个人中心</text>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			carouselItems: [
				{ text: '预约须知', bgColor: 'linear-gradient(135deg, #4A90E2, #357ABD)' },
				{ text: '就诊指南', bgColor: 'linear-gradient(135deg, #4A90E2, #357ABD)' },
				{ text: '停诊通知', bgColor: 'linear-gradient(135deg, #4A90E2, #357ABD)' },
				{ text: '医院导航', bgColor: 'linear-gradient(135deg, #4A90E2, #357ABD)' }
			],
			outpatientServices: [
				{ name: '候诊查询', id: 'waiting_query' },
				{ name: '自助缴费', id: 'self_payment' },
				{ name: '门诊费用', id: 'outpatient_fees' },
				{ name: '在线退款', id: 'online_refund' },
				{ name: '报告查询', id: 'report_query' },
				{ name: '病历查询', id: 'medical_record' },
				{ name: '复诊配药', id: 'follow_up' },
				{ name: '体检服务', id: 'physical_exam' },
				{ name: '电子发票', id: 'electronic_invoice' }
			],
			inpatientServices: [
				{ name: '住院充值', id: 'inpatient_recharge' },
				{ name: '住院费用', id: 'inpatient_fees' },
				{ name: '住院日清单', id: 'inpatient_daily' }
			],
			hospitalServices: [
				{ name: '医院介绍', id: 'hospital_intro' },
				{ name: '医院导航', id: 'hospital_nav' },
				{ name: '就医指南', id: 'medical_guide' },
				{ name: '健康百科', id: 'health_encyclopedia' }
			],
			currentIndex: 0,
			currentTab: 'home' // 默认选中首页
		}
	},
	methods: {
		onSwiperChange(e) {
			this.currentIndex = e.detail.current
		},
		onIndicatorClick(index) {
			this.currentIndex = index
		},
		onCarouselItemClick(item, index) {
			uni.showToast({
				title: `点击了${item.text}`,
				icon: 'none'
			})
			console.log('点击轮播图:', item)
		},
		handleServiceClick(service) {
			uni.showToast({
				title: `点击了${service.name}`,
				icon: 'none'
			})
			// 这里可以添加具体的业务逻辑
			console.log('点击服务:', service)
		},
		goToPersonal() {
			uni.navigateTo({
				url: '/pages/login/login'
			})
		},
		switchTab(tab) {
			this.currentTab = tab
			if (tab === 'personal') {
				this.goToPersonal()
			}
		}
	},
	onShow() {
		// 页面显示时，确保选中首页
		this.currentTab = 'home'
	}
}
</script>

<style scoped>
.container {
	min-height: 100vh;
	background-color: #f5f5f5;
	padding-bottom: 120rpx;
}

/* 页面标题 */
.page-header {
	display: flex;
	justify-content: center;
	margin-bottom: 30rpx;
	padding-top: 100rpx;
}

.page-title {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
}

/* 轮播图区域 */
.carousel-section {
	padding: 30rpx;
	padding-top: 20rpx;
	position: relative;
}

.carousel-container {
	position: relative;
	margin-bottom: 30rpx;
}

.carousel {
	height: 280rpx;
	border-radius: 24rpx;
	overflow: hidden;
	position: relative;
}

.carousel-item {
	height: 280rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 24rpx;
	background: linear-gradient(120deg, #4286f6 0%, #8fb6ff 100%);
	position: relative;
}

.carousel-text {
	color: #ffffff;
	font-size: 55rpx;
	font-weight: bold;
}

/* 自定义指示器 */
.custom-indicators {
	position: absolute;
	bottom: 20rpx;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	gap: 12rpx;
	z-index: 10;
}

.indicator-dot {
	width: 16rpx;
	height: 16rpx;
	background-color: rgba(255, 255, 255, 0.3);
	border-radius: 50%;
	transition: all 0.3s ease;
}

.indicator-dot.active {
	background-color: rgba(255, 255, 255, 0.9);
	width: 16rpx;
	height: 16rpx;
}

/* 服务板块通用样式 */
.service-section {
	margin: 30rpx;
	margin-top: 20rpx;
	background-color: #ffffff;
	border-radius: 20rpx;
	padding: 30rpx;
}

.section-header {
	display: flex;
	align-items: center;
	margin-bottom: 30rpx;
}

.section-line {
	width: 30rpx;
	height: 10rpx;
	background-color: #4A90E2;
	margin-right: 20rpx;
	border-radius: 5rpx;
}

.section-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #333;
}

/* 突出功能块 */
.feature-cards {
	display: flex;
	gap: 20rpx;
	margin-bottom: 30rpx;
}

.feature-card {
	flex: 1;
	height: 120rpx;
	border-radius: 16rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 30rpx;
	border: 1rpx solid;
}

.feature-card-red {
	background: linear-gradient(135deg, #FEF2F2, #FEE2E2);
	border-color: #FECACA;
}

.feature-card-green {
	background: linear-gradient(135deg, #F0FDF4, #DCFCE7);
	border-color: #BBF7D0;
}

.feature-content {
	display: flex;
	flex-direction: column;
}

.feature-title {
	color: #DC2626 !important;
	font-size: 32rpx;
	font-weight: bold;
	margin-bottom: 8rpx;
}

.feature-card-green .feature-title {
	color: #16A34A !important;
}

.feature-subtitle {
	color: #EF4444;
	font-size: 24rpx;
}

.feature-card-green .feature-subtitle {
	color: #22C55E;
}

.feature-icon {
	width: 60rpx;
	height: 60rpx;
	border-radius: 50%;
	position: relative;
}

.feature-icon-red {
	background-color: #FEF2F2;
	border: 1rpx solid #FECACA;
}

.feature-icon-red::before {
	content: '✓';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #DC2626;
}

.feature-icon-green {
	background-color: #F0FDF4;
	border: 1rpx solid #BBF7D0;
}

.feature-icon-green::before {
	content: '🔍';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #16A34A;
}

/* 服务网格 */
.service-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 24rpx;
}

.service-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 24rpx 16rpx;
	border-radius: 16rpx;
	background-color: #FAFAFA;
	border: 1rpx solid #F0F0F0;
	transition: all 0.3s ease;
}

.service-item:active {
	background-color: #F5F5F5;
	transform: scale(0.95);
}

.service-icon {
	width: 48rpx;
	height: 48rpx;
	background-color: #F3F4F6;
	border: 1rpx solid #E5E7EB;
	border-radius: 50%;
	margin-bottom: 16rpx;
	position: relative;
}

.service-text {
	font-size: 24rpx;
	color: #374151;
	text-align: center;
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.service-icon-waiting_query { background-color: #4A90E2; }
.service-icon-self_payment { background-color: #4CAF50; }
.service-icon-outpatient_fees { background-color: #FF9800; }
.service-icon-online_refund { background-color: #F44336; }
.service-icon-report_query { background-color: #9C27B0; }
.service-icon-medical_record { background-color: #00BCD4; }
.service-icon-follow_up { background-color: #673AB7; }
.service-icon-physical_exam { background-color: #009688; }
.service-icon-electronic_invoice { background-color: #795548; }
.service-icon-inpatient_recharge { background-color: #2196F3; }
.service-icon-inpatient_fees { background-color: #4CAF50; }
.service-icon-inpatient_daily { background-color: #FFEB3B; }
.service-icon-hospital_intro { background-color: #9E9E9E; }
.service-icon-hospital_nav { background-color: #FF5722; }
.service-icon-medical_guide { background-color: #03A9F4; }
.service-icon-health_encyclopedia { background-color: #4CAF50; }

/* 门诊服务图标 */
.service-icon-waiting_query::before {
	content: '⏰';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-self_payment::before {
	content: '💰';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-outpatient_fees::before {
	content: '📊';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-online_refund::before {
	content: '↩️';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-report_query::before {
	content: '📋';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-medical_record::before {
	content: '📄';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-follow_up::before {
	content: '💊';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-physical_exam::before {
	content: '🏥';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-electronic_invoice::before {
	content: '🧾';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

/* 住院服务图标 */
.service-icon-inpatient_recharge::before {
	content: '🏥';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-inpatient_fees::before {
	content: '💵';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-inpatient_daily::before {
	content: '📝';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

/* 医院服务图标 */
.service-icon-hospital_intro::before {
	content: '🏢';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-hospital_nav::before {
	content: '🗺️';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-medical_guide::before {
	content: '📖';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

.service-icon-health_encyclopedia::before {
	content: '📚';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: 32rpx;
	color: #4286f6;
}

/* 底部导航 */
.bottom-nav {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	height: 120rpx;
	background-color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: space-around;
	border-top: 1rpx solid #f0f0f0;
	padding-bottom: 20rpx;
}

.nav-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 10rpx 20rpx;
	border-radius: 12rpx;
	transition: all 0.3s ease;
}

.nav-item:active {
	background-color: #f8f9fa;
}

.nav-icon {
	width: 48rpx;
	height: 48rpx;
	margin-bottom: 8rpx;
	border-radius: 50%;
}

.nav-icon-home {
	background-color: #999;
	position: relative;
}

.nav-item-active .nav-icon-home {
	background-color: #4A90E2;
}

.nav-icon-home::before {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 24rpx;
	height: 24rpx;
	background-color: #ffffff;
	border-radius: 50%;
}

.nav-icon-person {
	background-color: #999;
	position: relative;
}

.nav-item-active .nav-icon-person {
	background-color: #4A90E2;
}

.nav-icon-person::before {
	content: '';
	position: absolute;
	top: 30%;
	left: 50%;
	transform: translateX(-50%);
	width: 20rpx;
	height: 20rpx;
	background-color: #ffffff;
	border-radius: 50%;
}

.nav-icon-person::after {
	content: '';
	position: absolute;
	bottom: 20%;
	left: 50%;
	transform: translateX(-50%);
	width: 32rpx;
	height: 16rpx;
	background-color: #ffffff;
	border-radius: 8rpx;
}

.nav-text {
	font-size: 24rpx;
	color: #999;
}

.nav-item-active .nav-text {
	color: #4A90E2;
	font-weight: bold;
}

/* 响应式适配 */
@media screen and (max-width: 750rpx) {
	.service-grid {
		grid-template-columns: repeat(3, 1fr);
	}
	
	.feature-cards {
		flex-direction: column;
		gap: 15rpx;
	}
	
	.feature-card {
		height: 100rpx;
	}
}

@media screen and (max-width: 600rpx) {
	.service-grid {
		grid-template-columns: repeat(2, 1fr);
	}
	
	.carousel {
		height: 160rpx;
	}
	
	.carousel-text {
		font-size: 32rpx;
	}
}

/* 安全区域适配 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
	.container {
		padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
	}
	
	.bottom-nav {
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
	}
}
</style>
